﻿using System;
using System.Collections.Generic; 
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing; 

namespace CardControlLibrary
{
    public class CardThreadSafeOpperations
    {

        internal delegate void AddControlDelegate(Control Parent, Control Child);
        private void AddControlThreadSafe(Control Parent, Control Child)
        { Parent.Controls.Add(Child); }
        public void AddControl(Control Parent, Control Child)
        {
            if (Parent.InvokeRequired)
            {
                AddControlDelegate Obj = new AddControlDelegate(this.AddControlThreadSafe);
                Parent.BeginInvoke(Obj, new object[] { Parent, Child });
            }
            else
                AddControlThreadSafe(Parent, Child);
        }


        internal delegate void RemoveControlDelegate(Control Parent, Control Child);
        private void RemoveControlThreadSafe(Control Parent, Control Child)
        { Parent.Controls.Remove(Child); }
        public void RemoveControl(Control Parent, Control Child)
        {
            if (Parent.InvokeRequired)
            {
                RemoveControlDelegate Obj = new RemoveControlDelegate(this.RemoveControlThreadSafe);
                Parent.BeginInvoke(Obj, new object[] { Parent, Child });
            }
            else
                RemoveControlThreadSafe(Parent, Child);
        }

        internal delegate void SetAnchorPropertyDelegate(Control ctrl, AnchorStyles style);
        private void SetAnchorPropertyThreadSafe(Control ctrl, AnchorStyles style)
        { ctrl.Anchor = style; }
        public void SetAnchor(Control ctrl, AnchorStyles style)
        {
            if (ctrl.InvokeRequired)
            {
                SetAnchorPropertyDelegate Obj = new SetAnchorPropertyDelegate(this.SetAnchorPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, style });
            }
            else
                SetAnchorPropertyThreadSafe(ctrl, style);
        }


        
        internal delegate void SetWidthPropertyDelegate(Control ctrl, int width);
        private void SetWidthPropertyThreadSafe(Control ctrl, int width)
        { ctrl.Width = width; }
        public void SetWidth(Control ctrl, int width)
        {
            if (ctrl.InvokeRequired)
            {
                SetWidthPropertyDelegate Obj = new SetWidthPropertyDelegate(this.SetWidthPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, width });
            }
            else
                SetWidthPropertyThreadSafe(ctrl, width);
        }

        internal delegate void SetHeightPropertyDelegate(Control ctrl, int height);
        private void SetHeightPropertyThreadSafe(Control ctrl, int height)
        { ctrl.Height = height; }
        public void SetHeight(Control ctrl, int height)
        {
            if (ctrl.InvokeRequired)
            {
                SetHeightPropertyDelegate Obj = new SetHeightPropertyDelegate(this.SetWidthPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, height });
            }
            else
                SetHeightPropertyThreadSafe(ctrl, height);
        }

        internal delegate void SetDocumentTextDelegate(WebBrowser ctrl, string text);
        private void SetDocumentTextPropertyThreadSafe(WebBrowser ctrl, string text)
        { ctrl.DocumentText = text; }
        public void SetDocumentText(WebBrowser ctrl, string text)
        {
            if (ctrl.InvokeRequired)
            {
                SetDocumentTextDelegate Obj = new SetDocumentTextDelegate(this.SetDocumentTextPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, text });
            }
            else
                SetTextPropertyThreadSafe(ctrl, text);
        }

        internal delegate void SetTextPropertyDelegate(Control ctrl, string text);
        private void SetTextPropertyThreadSafe(Control ctrl, string text)
        { ctrl.Text = text; }
        public void SetText(Control ctrl, string text)
        {
            if (ctrl.InvokeRequired)
            {
                SetTextPropertyDelegate Obj = new SetTextPropertyDelegate(this.SetTextPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, text });
            }
            else
                SetTextPropertyThreadSafe(ctrl, text);
        }

        internal delegate void SetLocationPropertyDelegate(Control ctrl, Point point);
        private void SetLocationPropertyThreadSafe(Control ctrl, Point point)
        { ctrl.Location = point; }
        public void SetLocation(Control ctrl, Point point)
        {
            if (ctrl.InvokeRequired)
            {
                SetLocationPropertyDelegate Obj = new SetLocationPropertyDelegate(this.SetLocationPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, point });
            }
            else
                SetLocationPropertyThreadSafe(ctrl, point);
        }

        internal delegate void SetImagePropertyDelegate(PictureBox ctrl, Image image);
        private void SetImagePropertyThreadSafe(PictureBox ctrl, Image image)
        { ctrl.Image = image; }
        public void SetImage(PictureBox ctrl, Image image)
        {
            if (ctrl.InvokeRequired)
            {
                SetImagePropertyDelegate Obj = new SetImagePropertyDelegate(this.SetImagePropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, image });
            }
            else
                SetImagePropertyThreadSafe(ctrl, image);
        }
        internal delegate void SetVisibilityPropertyDelegate(Control ctrl, bool visible);
        private void SetVisibilityPropertyThreadSafe(Control ctrl, bool visible)
        { if (visible) ctrl.Show(); else ctrl.Hide(); }
        public void SetVisibility(Control ctrl, bool visible)
        {
            if (ctrl.InvokeRequired)
            {
                SetVisibilityPropertyDelegate Obj = new SetVisibilityPropertyDelegate(this.SetVisibilityPropertyThreadSafe);
                ctrl.BeginInvoke(Obj, new object[] { ctrl, visible });
            }
            else
                SetVisibilityPropertyThreadSafe(ctrl, visible);
        }
    
    }
}
